import type { ConsultationNotice, LawyerDetail, RecommendItem, RecommendLawyerResponse, RecommendListResponse, SafeguardList, ServerTypeList, ServiceItem, ServiceOption } from './types/detail'
import type { PageParams, PageResult } from '@/http/types'
import { http } from '@/http/alova'

export function submitCase(lawyerId?: number) {
  return http.Post<RecommendListResponse>('/api/v1/home/userCommentCount', {
    lawyerId,
  })
}
export function getLawyerList(pageParams: PageParams, lawyerTop?: number) {
  return http.Post<PageResult<RecommendItem>>('/api/v1/home/userComment', {
    lawyerTop,
    page: pageParams.page,
    size: pageParams.pageSize,
  }, {
    transform(raw) {
      // raw 是 unknown，需要先断言
      const res = raw as {
        records?: RecommendItem[]
        total?: number
        pages?: number
        size?: number
        [key: string]: any
      }

      return {
        list: res.records ?? [],
        total: res.total ?? 0,
        page: res.pages ?? pageParams.page,
        pageSize: res.size ?? pageParams.pageSize,
      } satisfies PageResult<RecommendItem>
    },
  })
}
export function safeguardList(lawyerId?: number) {
  return http.Post<SafeguardList>('/api/v1/home/lawyerServer', {
    lawyerId,
  })
}
export function lawyerServiceFirst(lawyerId?: number) {
  return http.Post<ServiceItem>('/api/v1/home/lawyer-server-first', {
    lawyerId,
  })
}
export function lawyerDetailServerType(type?: number) {
  return http.Post<ServerTypeList>('/api/v1/home/lawyerDetailServerType', {
    type,
  })
}
export function lawyerServerDetail(lawyerId?: number, oneType?: number, twoType?: number) {
  return http.Post<ServiceOption>('/api/v1/home/lawyer-server-detail', {
    lawyerId,
    oneType,
    twoType,
  })
}
export function lawyerConsultExplain() {
  return http.Post<ConsultationNotice>('/api/v1/home/consultExplain')
}

export function recommendLawyerList(lawyerId?: number) {
  return http.Post<RecommendLawyerResponse>('/api/v1/home/recommendLawyer', {
    lawyerId,
  })
}
export function lawyerBasic(id?: number) {
  return http.Post<LawyerDetail>('/api/v1/home/lawyer-basic', {
    id,
  })
}
